from django import forms
from django.forms import widgets
from django.forms.models import ModelForm
from jrcmodel.models import MyConstants
from tracking.models import TrackRecordForex, TrackRecordFutures
from django.forms.extras.widgets import SelectDateWidget

class YearMonthTextForm(forms.Form):
    months = [(0, u"Month")]
    years = [(0, "Year")]
    
    for m in range(1, 13):
        months.append((m, m))
    for y in range(2000, 2020):
        years.append((y, y))
        
    year = forms.IntegerField(widget = widgets.Select(choices = years))
    month = forms.IntegerField(widget = widgets.Select(choices = months))
#    remarks = forms.CharField(widget = widgets.TextInput({"style": "border: 0px; width: 600px;", "readonly": "readonly"}))
    text = forms.CharField(max_length = 16384, widget = widgets.Textarea({"cols": "130", "rows": "50", "wrap": "off", "style": "font-family: Courier New; font-size: small;"}))
#    date_fmt = forms.CharField(max_length = 32, widget = widgets.Select(choices = MyConstants.DATE_FMT_CHOICES))
    
    def clean(self):
        cleaned_data = self.cleaned_data 
        y = cleaned_data.get("year")
        if y < 1:
            self._errors["year"] = self.error_class([u"Choose year"])
            del cleaned_data["year"]

        m = cleaned_data.get("month")
        if y < 1:
            self._errors["month"] = self.error_class([u"Choose month"])
            del cleaned_data["month"]

        return cleaned_data

class TrackRecordForexForm(ModelForm):
    class Meta:
        model = TrackRecordForex
        widgets = {
            "date": SelectDateWidget(years = range(2008, 2021))
        }

class TrackRecordFuturesForm(ModelForm):
    class Meta:
        model = TrackRecordFutures
        widgets = {
            "date": SelectDateWidget(years = range(2008, 2021))
        }

